<!DOCTYPE html>
<html>
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <title>忘记密码</title>
    <link rel="stylesheet" href="/home/layui/css/layui.css" media="all"/>
    <link rel="stylesheet" href="/home/login/css/login.css" media="all"/>

</head>
<body>
<style>
    body {
        background-color: #009688;
    }

    .layui-input {
        background-color: inherit;
        padding-left: 30px;
    }
</style>

<!-- 忘记密码 -->
<div class="zyl_lofo_main">
    <fieldset class="layui-elem-field layui-field-title zyl_mar_02">
        <legend>XXX快递 - 忘记密码</legend>
    </fieldset>
    <div class="layui-row layui-col-space15">
        <form class="layui-form zyl_pad_01" id="forgetForm">
            <div class="layui-col-sm12 layui-col-md12">
                <div class="layui-form-item">
                    <input type="text" name="mobile" id="mobile" autocomplete="off"
                           placeholder="请输入手机号" class="layui-input">
                    <i class="layui-icon layui-icon-username zyl_lofo_icon"></i>
                </div>
            </div>
            <div class="layui-col-sm12 layui-col-md12">
                <div class="layui-form-item">
                    <input type="email" name="email" autocomplete="off"
                           placeholder="请输入邮箱进行验证" class="layui-input" id="email">
                    <i class="layui-icon layui-icon-email zyl_lofo_icon"></i>
                </div>
            </div>
            <div class="layui-col-sm12 layui-col-md12">
                <div class="layui-row">
                    <div class="layui-col-xs4 layui-col-sm4 layui-col-md4" style="width: 210px">
                        <div class="layui-form-item">
                            <input type="text" name="reCode" id="reCode"
                                   autocomplete="off" placeholder="请输入邮箱验证码" class="layui-input" maxlength="4">
                            <i class="layui-icon layui-icon-vercode zyl_lofo_icon"></i>
                        </div>
                    </div>
                    <div class="layui-col-xs4 layui-col-sm4 layui-col-md4">
                        <div class="zyl_lofo_vercode ">
                            <input type="button" value="点击发送" class="layui-btn layui-btn-primary send-code-btn"/>
                            <input type="button" value="重新发送" style="display: none;"
                                   class="layui-btn layui-btn-normal layui-btn-disabled code-btn" disabled/>
                        </div>
                    </div>
                </div>
            </div>
            <div class="layui-col-sm12 layui-col-md12">
                <div class="layui-form-item">
                    <input type="password" name="password" id="password" autocomplete="off"
                           placeholder="请输入新密码" class="layui-input">
                    <i class="layui-icon layui-icon-password zyl_lofo_icon"></i>
                </div>
            </div>
            <div class="layui-col-sm12 layui-col-md12">
                <button class="layui-btn layui-btn-fluid" lay-submit id="forget" lay-filter="forget">重置密码</button>
            </div>
            <div class="layui-col-sm4 layui-col-md4" style="margin: 20px;left: 20px;font-size: 15px">
                <a href="/home/index/register">还没账号?点击注册</a>
            </div>
            <div class="layui-col-sm4 layui-col-md4" style="margin: 20px;left: 20px;font-size: 15px">
                <a href="/home/index/login">已有账号?点击登录</a>
            </div>
        </form>

    </div>
</div>
<!-- 登录结束 -->

<script type="text/javascript" src="/admin/js/jquery.min.js"></script>
<script type="text/javascript" src="/home/layui/layui.js"></script>
<script type="text/javascript" src="/home/js/msg.js"></script>
<script type="text/javascript" src="/home/login/assembly/jqarticle/jparticle.min.js"></script>
<script type="text/javascript" src="/home/login/js/login.js"></script>
<script type="text/javascript" src="/home/login/js/three.min.js"></script>
<script>

    $(function () {
        init();		//初始化
        animate();	//动画效果
    });

    //按钮不能连续点击
    var countdown = 60;  // 时长
    function setButton() {
        $(".send-code-btn").hide();
        $(".code-btn").show();
        var timer = setInterval(function () {
            if (countdown == 0) {
                clearInterval(timer);
                $(".send-code-btn").show();
                $(".code-btn").hide();
                countdown = 60;
            }
            $(".code-btn").val('(' + (countdown - 1) + '秒)');
            countdown--;
        }, 1000);
    };

    //验证码发送
    $(".send-code-btn").click(function () {
        var email = $('#email').val();
        if (msg.isEmpty(email)) {
            errorMsg("邮箱为空");
            return;
        }
        if (!msg.isEmail(email)) {
            errorMsg("邮箱格式错误");
            return;
        }
        $.ajax({
            url: '/send_email/generate_code',
            data: {email: email, method: "ylrc_forget_password_code"},
            type: 'POST',
            dataType: 'json',
            success: function (data) {
                if (data.code == 0) {
                    successMsg('发送成功注意查收!');
                    setButton();
                } else {
                    errorMsg(data.msg);
                }
            },
            error: function (data) {
                errorMsg("邮箱不存在");
            }
        });
    });


    $("#forget").click(function () {
        var mobile = $("#mobile").val();
        var email = $("#email").val();
        var reCode = $("#reCode").val();
        var password = $("#password").val();
        if (mobile == "") {
            errorMsg("手机号不能为空");
            return;
        }
        if (!msg.isPhone(mobile)) {
            errorMsg("手机号格式不正确");
            return;
        }
        if (email == "") {
            errorMsg("邮箱不能为空");
            return;
        }
        if (!msg.isEmail(email)) {
            errorMsg("邮箱格式不正确");
            return;
        }
        if (reCode == "") {
            errorMsg("验证码不能为空");
            return;
        }
        if (reCode.length != 4) {
            errorMsg("验证码长度不正确");
            return;
        }
        if (password == "") {
            errorMsg("密码不能为空");
            return;
        }
        if (password.length < 6 || password.length > 12) {
            errorMsg("密码只能为6-12位");
            return;
        }
        var data = $("#forgetForm").serialize();
        $.ajax({
            url: '/home/index/forget',
            type: 'POST',
            data: data,
            dataType: 'json',
            success: function (data) {
                if (data.code == 0) {
                    successMsg("重置密码成功");
                    setTimeout(function () {
                        window.location.href = "/home/index/login";
                    }, 1000);
                } else {
                    errorMsg(data.msg);
                }
            }
        });
    });


    layui.use('form', function () {
        var form = layui.form;
        //监听注册提交
        form.on('submit(forget)', function (data) {
            return false;
        });
    });

</script>
</body>
</html>
